package com.stx.blog.action;

import java.util.Date;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.stx.blog.service.UserService;
import com.stx.blog.vo.UserVo;

public class ChangeBaseAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private UserVo uv=null;
	private UserService us;
	public UserVo getUv() {
		return uv;
	}
	public void setUv(UserVo uv) {
		this.uv = uv;
	}
	public UserService getUs() {
		return us;
	}
	public void setUs(UserService us) {
		this.us = us;
	}
	
	public String changeBase(){
		uv.setBlogLastmodifytime(new Date());
		try {
			us.changeBase(uv);
		} catch (Exception e) {
			e.printStackTrace();
			addActionError("此用户名已存在,请重新输入");
			return "input";
		}
		uv=us.getUsesr(uv.getBuid());
		HttpSession s=ServletActionContext.getRequest().getSession();
		s.removeAttribute("user");
		s.setAttribute("user", uv);
		
//			uv=us.getUser(uv);
//			s.removeAttribute("user");
//			s.setAttribute("user", uv);
			addActionError("基本资料修改完毕");
		return "update";
	}
}
